package cn.ipanel.bigdata.dw.dim

import cn.ipanel.bigdata.boot.config.Configuration
import cn.ipanel.bigdata.boot.logger.Logger

package object mysql {

  val T_EXTRA_DEVICE    : ExtraDevice.type   = ExtraDevice
  val T_EXTRA_HOME      : ExtraHome.type     = ExtraHome

  final lazy val ALIAS_DEVICE            = "ali_device"
  final lazy val ALIAS_DEVICE_APP        = "ali_device_app"
  final lazy val ALIAS_WORK_ORDER        = "ali_work_order"
  final lazy val ALIAS_SYS_DICT          = "ali_sys_dict"
  final lazy val ALIAS_SYS_DICT_DETAIL   = "ali_sys_dict_detail"

  def getTableName(alias: String): String = {
    getTableName(alias, null)
  }

  def getTableName(alias: String, defTable: String): String = {
    val info = Configuration.getTableInfo(alias)
    if (null == info) {
      Logger.I("table alias " + alias + " use default name " + defTable)
      return defTable
    }
    info.name
  }

  def getDatabaseName(alias: String): String = {
    getDatabaseName(alias, "gateway_device")
  }

  def getDatabaseName(alias: String, defDatabase: String): String = {
    val info = Configuration.getTableInfo(alias)
    if (null == info) {
      Logger.I("database alias " + alias + " use default name " + defDatabase)
      return defDatabase
    }
    info.database
  }

}
